package com.L.yygh.user.controller;

import com.L.yygh.common.result.Result;
import com.L.yygh.model.user.UserInfo;
import com.L.yygh.user.Service.UserInfoService;
import com.L.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable long page,
                       @PathVariable long limit,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> userInfoPage = new Page<>(page,limit);
        Page<UserInfo> page1 = userInfoService.selectPage(userInfoPage,userInfoQueryVo);
        return Result.ok(page1);
    }

    //用户锁定
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId,
                       @PathVariable Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();
    }

    //根据用户id得到用户详情功能
    @GetMapping("/show/{userId}")
    public Result show(@PathVariable Long userId){
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    //认证审批功能
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Integer userId,
                           @PathVariable Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
